<?php

header("Content-type:text/html; charset=UTF-8");

function Add_addslashes(&$array) {
    if (is_array($array)) {
        foreach ($array as $key => $value) {
            if (!is_array($value)) {
                $array[$key] = addslashes($value);
            } else {
                Add_addslashes($array[$key]);
            }
        }
    }
}

if (function_exists('get_magic_quotes_gpc')) {
    if (!get_magic_quotes_gpc()) {
        Add_addslashes($_POST);
        Add_addslashes($_GET);
        Add_addslashes($_COOKIE);
    }
} else {
    Add_addslashes($_POST);
    Add_addslashes($_GET);
    Add_addslashes($_COOKIE);
}

//注销部分预定义常量，规范程序员代码写法
unset($_ENV, $HTTP_ENV_VARS, $_REQUEST, $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_POST_FILES, $HTTP_COOKIE_VARS);

//目录常量
define('YSP_ROOT_BASE', rtrim(str_replace('\\', '/', dirname(__FILE__)), '\/'));

/**
 * 魔术方法，自动载入类文件
 * @param string $class_name 类名
 */
function __autoload($class_name) {
    //分析文件路径
    $file_name_arr = explode('Ysp', $class_name);
    $class_file_path = YSP_ROOT_BASE . '/' . strtolower($file_name_arr[0]) . "/$class_name.class.php";
    if (file_exists($class_file_path)) {
        require_once $class_file_path;
    }
}

//当前页面URL
define('URL', "http://{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_NAME']}?{$_SERVER['QUERY_STRING']}");
define('URL_HTML', "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
